<template>
  <div class="epsInfoWrap">
    <el-row>
      <el-form
          :inline="true"
          :model="searchParams"
          style="width: 100%"
          size="small"
          class="formInline"
          :modal-append-to-body="false"
      >
        <el-form-item label="商品及服务编码：" style="max-width: 340px">
          <el-input
              style="width: 160px"
              v-model="searchParams.gstcmCode"
          ></el-input>
        </el-form-item>
        <el-form-item label="商品及服务名称：" style="max-width: 340px">
          <el-input
              style="width: 160px"
              v-model="searchParams.sphfwmc"
          ></el-input>
        </el-form-item>
        <el-form-item label="企业商品及服务编码：" style="max-width: 340px">
          <el-input
              style="width: 160px"
              v-model="searchParams.epsCode"
          ></el-input>
        </el-form-item>
        <el-form-item label="企业商品及服务名称：" style="max-width: 340px">
          <el-input
              style="width: 160px"
              v-model="searchParams.epsName"
          ></el-input>
        </el-form-item>


        <el-form-item
        >
          <el-button @click="queryInfo" type="primary">查询</el-button>
          <el-button @click="onResize">重置</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row style="margin-bottom: 5px">
      <el-button @click="addDialog('add')" type="primary" size="small" v-if="hasAuth('VMS_FULL_EPS_ADD')">新增</el-button>
      <el-button @click="addDialog('update')" type="primary" size="small" v-if="hasAuth('VMS_FULL_EPS_ADD')">修改</el-button>
      <el-button @click="deleteDialog" type="primary" size="small" v-if="hasAuth('VMS_FULL_EPS_DELETE')">删除</el-button>
    </el-row>
    <tableList
        :showIndex="true"
        :data="listDetails"
        border
        :heightMin="130"
        :loading="loading"
        :keySet="keySet"
        :autoHeight="true"
        :tableData="listDetails"
        :paginationShow="true"
        :pageNumber="pages.current"
        :pageSize="pages.size"
        :total="pages.total"
        :radioSelect="true"
        @radioHandleCurrentChange="radioHandleCurrentChange"
        @handleSizeChange="handleSizeChange"
        @rowClick="rowClick"
        @handleCurrentChange="handleCurrentChange"
    >
    </tableList>

    <add-dialog  ref="addOrUpdate" ></add-dialog>
  </div>

</template>
  
  <script>

import DictSelect from "@/views/invoiceTemplate/components/DictSelect/DictSelect.vue";
import tableList from "@/components/tableList/index.vue";
import { queryServiceInfo,deleteById} from '@/api/serviceInformationManage.js'
import mixinTable from "@/mixin/mtable";

import AddDialog from "@/views/serviceInformationManage/components/addDialog.vue";

export default {
    name: 'serviceInformationManage',
    components:{
      AddDialog,
      tableList,
      DictSelect
    },
    mixins: [mixinTable],
    created(){
      this.getList()
    },
    data() {
        return {
          loading: false,
          listDetails: [],
          keySet: [
            {
              label: '应用范围',
              englishName: 'application',
              width: '200px'
            },
            {
              label: '企业商品及服务编码',
              englishName: 'epsCode',
              width: '200px'
            },
            {
              label: '企业商品及服务名称',
              englishName: 'epsName',
              width: '200px'
            },
            {
              label: '父级编码',
              englishName: 'parentCode',
              width: '100px'
            },
            {
              label: '商品及服务编码',
              englishName: 'gstcmCode',
              width: 170
            },
            {
              label: '商品及服务名称',
              englishName: 'sphfwmc',
              width: 400
            },
            {
              label: '商品和服务分类简称',
              englishName: 'sphfwfljc',
              width: 300
            },
            {
              label: '税率',
              englishName: 'zzssl',
              width: '80px'
            },
            {
              label: '差额征税',
              englishName: 'cezs',
              width: '80px'
            },
            {
              label: '特定要素',
              englishName: 'tdyslxdmText',
              width: '120px'
            },
            {
              label: '计量单位',
              englishName: 'jldwText',
              width: '80px'
            },
            {
              label: '优惠政策标识',
              englishName: 'yhzcbsText',
              width: 120
            },
            {
              label: '计税方法',
              englishName: 'jsffText',
              width: '80px'
            },
            {
              label: '征税项目',
              englishName: 'zsxmText',
              width: '80px'
            },
            {
              label: '启用日期',
              englishName: 'qyrq',
              width: 100
            },
            {
              label: '停用日期',
              englishName: 'tyrq',
              width: 100
            },

          ],
          selectRow:null,
        }
    },
    methods:{
      /**
       * 查询
       * 分页是分页\
       * 查询是查询,
       * 两个操作,本身就应该分开做,,,,,,
       */
      queryInfo(){
          this.pages.current=1
          this.getList()
      },

      /**
       * 查询列表数据
       * @param params
       * @returns {Promise<void>}
       */
      async getList() {
        this.loading = true
        let {data, code, message} = await queryServiceInfo({
          gstcmCode: this.searchParams.gstcmCode,
          sphfwmc: this.searchParams.sphfwmc,
          epsName: this.searchParams.epsName,
          epsCode: this.searchParams.epsCode,
          pageNo: this.pages.current,
          pageSize: this.pages.size,
        })

        if (code == 200) {
          this.loading = false
          // this.listDetails = data.records
          this.listDetails = data.records.map(item=>{
                                return {
                                    ...item
                                }
                            })
          this.pages.total = data.total
          this.pages.current = data.current
          this.pages.size = data.size
        } else {
          // this.$message({
          //   type: 'success',
          //   message: message,
          // })
        }

      },
      /**
       * 重置参数
       */
      onResize() {
        //this.onResizeFn()

        this.searchParams = {
          input1:'',
          input2:'',
          input3:'',
          select1:'',
          select2:'',
          select3:'',
          date1: '',
          date2: '',
        }
        this.getList()
      },
      addDialog(params) {

        this.$refs.addOrUpdate.addDialogParam=params;
        this.$refs.addOrUpdate.addVisible=true;
        if (params==='add'){
          this.$refs.addOrUpdate.dialogTitle='新增企业商品及服务信息';
          this.$refs.addOrUpdate.clearInfo();
        }else if (params==='update'){
          if(!this.selectRow){
              this.$message({
                type: 'error',
                message: '请选择一条数据',

              })
            this.$refs.addOrUpdate.addVisible=false;
            return;
          }

          this.$refs.addOrUpdate.dialogTitle='修改企业商品及服务信息';
          this.$refs.addOrUpdate.extracted2();
          this.$refs.addOrUpdate.initInfo(this.selectRow.id)
        }
      },
      rowClick(){

      },
      async deleteDialog(){
        if(!this.selectRow){
          this.$message({
            type: 'error',
            message: '请选择一条数据',

          })
          return;
        }
        if (this.selectRow.id) {
          this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            let {data, code, message} =  deleteById(
                this.selectRow.id
            );
            this.getList()

          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            });
          });
        }
      },
      // 单选
      radioHandleCurrentChange(val) {
        this.selectRow = val
      },
    }
}
</script>

  <style lang = "scss" scoped>
  @import '@/style/variables.scss';
  .epsInfoWrap {
    box-sizing: border-box;
    //   padding: 10px;
    .head {
      display: flex;
      height: 18px;
      align-items: center;
      margin-bottom: 4px;
      margin-top: 4px;

      .colCLas {
        width: 4px;
        height: 100%;
        background-color: $allBg;
        margin-right: 12px;
      }

      .info {
        height: 100%;
        display: flex;
        align-items: center;
      }
    }

  }
</style>
  